﻿using System;
using WpfAi.Enum;
using WpfAi.Core;
using WpfAi.Model;
using System.Threading;
using Base.Core;

namespace WpfAi.TestModule
{
    /// <summary>
    /// 接收串口数据并事件通知测试项类
    /// </summary>
    public class EventPublisher
    {
        static bool hasInit;
        protected static ResponseWarp resWarp = null;
        protected static AutoResetEvent autoResetEvent = new AutoResetEvent(false);
        public EventPublisher()
        {
            if (!hasInit)
            {
                SingletonProvider<Analysis>.Instance.OnPlate += Instance_OnPlate;
                hasInit = true;
            }
        }
        /// <summary>
        /// 全局信号控制
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Instance_OnPlate(object sender, ResponseWarp e)
        {
            resWarp = e;
            if (
                (e.Command == StaticCommand.U_CameraPic && e.Number != 239)
                || e.Command == StaticCommand.U_Camera
                || e.Command == StaticCommand.U_Reset
                || e.Command == StaticCommand.U_HeartBeat
                || e.Command == StaticCommand.U_SearchStatus
                || e.Command == StaticCommand.U_WriteSn
                || e.Command == StaticCommand.U_ReadSn)
                return;
            autoResetEvent.Set();
            LogHelper.Log.Info(resWarp.Title + ":释放信号" + DateTime.Now.ToString("yyyyMMdd HH:mm:ss fff") + " 报文：" + resWarp.HexByte);
        }
    }
}